class Solution {
public:
    int change(int amount, vector<int>& coins) {
        int n = coins.size();
        vector<uint64_t> dp(amount + 1, 0);
        dp[0] = 1;

        for (int i = 1; i < n + 1; i++)
            for (int j = coins[i - 1]; j < amount + 1; j++)
                dp[j]  += dp[j - coins[i - 1]];
                    

        return dp[amount];
    }
};








//dp[i][j]表示: 考虑前i个钱币，其价值总和为j时的组合总数
//如果第i个钱币不拿 dp[i][j] = dp[i - 1][j]
//如果第i个钱币拿1个 dp[i][j] = dp[i - 1][j - vi]
//如果第i个钱币拿2个 dp[i][j] = dp[i - 1][j -2vi]
    //即，dp[i][j] = dp[i - 1][j] + dp[i - 1][j - vi] + dp[i - 1][j -2vi] + dp[i - 1][j - 3vi].....
    //令j = j - vi, dp[i][j - vi] = dp[i - 1][j - vi] + dp[i - 1][j - 2vi] + dp[i - 1][j -3vi] + dp[i - 1][j - 4vi].....
    //dp[i][j] = dp[i - 1][j] + dp[i][j - vi]
// class Solution {
// public:
//     int change(int amount, vector<int>& coins) {
//         int n = coins.size();
//         vector<vector<uint64_t>> dp(n + 1, vector<uint64_t>(amount + 1, 0));
//             dp[0][0] = 1;

//         for (int i = 1; i < n + 1; i++)
//         {
//             for (int j = 0; j < amount + 1; j++)
//             {
//                 dp[i][j] = dp[i - 1][j];
//                 if (j >= coins[i - 1])
//                 {
//                     dp[i][j]  += dp[i][j - coins[i - 1]];
                    
//                 }
//             }
//         }

//         return dp[n][amount];
//     }
// };